<html>

<head>

	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<title>飞的更高</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
	<div align="center">
		<font color="#FFFF03" size="15">欢迎使用航空票务管理系统
		</font>
	</div>
	<br>

	<div class="form-group col-md-offset-1">
		<label for="username">用户名</label>
		<input type="text" class="form-control" id="username" placeholder="username">
	</div><br>
	<div class="form-group col-md-offset-1">
		<label for="password">密码</label>
		<input type="password" class="form-control" id="password" placeholder="Password">
		<input type="radio" value="0" id = "radio" name="radiobutton" checked="checked"/>用户登录
		<input type="radio" value="1" id = "radio" name="radiobutton" />管理员登陆
	</div>

	<div class="col-md-offset-1">
		<button type="button" class="layui-btn layui-btn-radius layui-btn-normal btn-block btn btn-primary" onclick="login()">登陆</button>
		<a href="register.html" class="btn-block btn btn-success"> 注册</a>
	</div>
	<script src="js/jquery.min.js"></script>
	<script src="js/jquery-3.3.1.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
</body>

<script type="text/javascript">
	function login() {
		<!--alert(1)-->	
			var username = $("#username").val();
			var password = $("#password").val();
			var radio = $('input:radio[name="radiobutton"]:checked').val();
			//alert(radio);
			
			if (username == "") {
				alert("用户名不能为空");
				return;
			}
			
			if(password == ""){
				alert("密码不能为空");
				return ;
			}
			var allData = {
					"username":username,
					"password":password,
					"admin":radio,
					
			}
			
			$.ajax({
				async: false,
				type:"POST",
				url: "http://localhost:8080/user/login",
				dataType:"json",
				 contentType:"application/json;charset=utf-8",
				data:JSON.stringify(allData),
				success:function(data){
					alert(data.message);
					if(data.admin == 1 && data.status==1){
						window.location.href = "http://localhost:8080/admin.html";
					}else if(data.status == 1){
						window.location.href = "http://localhost:8080/index.html";
					}else{
						window.location.href = "http://localhost:8080/login.html";
					}
					
					return;
				},
				error: function(data) {
					alert("请登录！");
					return;
				},
			})
	
	}
	
</script>

</html>
